package com.highstockings.utils;

/**
 * Created by diablo13064 on 2018/4/12.
 */
public class CalculatorUtil {
    /**
     * 加权平均算法
     * @param baseNum
     * @param weight
     * @return
     */
    public static Float CWeightAverage(float[] baseNum, int[] weight) {
        float result=0;
        if (baseNum.length != weight.length) {
            return 5.0f;
        } else {
            float f = 0;
            int w = 0;
            for(int i=0;i<baseNum.length;i++) {
                f += baseNum[i] * weight[i];
                w += weight[i];
            }
            result = f / w;
        }
        //保留一位小数（保留几位就乘几）
        return (float)(Math.round(result*10))/10;
    }
}
